﻿using PLCS.Application.Contracts.HisTaskApp.Dtos;
using PLCS.Application.Contracts.TaskApp.Dtos;
using PLCS.Client.IService.OrderTask;
using Volo.Abp.Application.Dtos;

namespace PLCS.Client.Service.OrderTask;

public class HisInstructionService : BaseService<HisInstructionDto, HisInstructionDto>, IHisInstructionService
{
    public override async Task<IEnumerable<HisInstructionDto>> GetListAsync()
    {
        RequestParam requestParam = new(method: Method.Get, route: $"hisInstruction");
        var apiRes = await restClient.ExecuteAsync<PagedResultDto<HisInstructionDto>>(requestParam);
        if (apiRes.Status)
            return apiRes.Data.Items;
        else
            return Enumerable.Empty<HisInstructionDto>();
    }

    public async Task<PagedResultDto<HisInstructionDto>> GetListBySearchAsync(int skipCount, int maxResultCount, string? instructionNo, string? StartTime, string? EndTime)
    {
        var route = $"hisInstruction/bySearch?SkipCount={skipCount}&MaxResultCount={maxResultCount}";
        if (!string.IsNullOrEmpty(instructionNo))
            route = route + $"&instructionNo={instructionNo}";
        if (!string.IsNullOrEmpty(StartTime))
            route += $"&startTime={StartTime}";
        if (!string.IsNullOrEmpty(EndTime))
            route += $"&endTime={EndTime}";
        RequestParam requestParam = new(method: Method.Get, route: route);
        var apiRes = await restClient.ExecuteAsync<PagedResultDto<HisInstructionDto>>(requestParam);
        if (apiRes.Status)
            return apiRes.Data;
        else
            return new PagedResultDto<HisInstructionDto>();
    }

    public async Task<PagedResultDto<HisInstructionDto>> GetPagedAsync(int skipCount, int maxResultCount)
    {
        RequestParam requestParam = new(method: Method.Get, route: $"hisInstruction?SkipCount={skipCount}&MaxResultCount={maxResultCount}");
        var apiRes = await restClient.ExecuteAsync<PagedResultDto<HisInstructionDto>>(requestParam);
        if (apiRes.Status)
            return apiRes.Data;
        else
            return new PagedResultDto<HisInstructionDto>();
    }
}